package com.li.youhappygo.config;

import com.li.youhappygo.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Component
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(loginInterceptor)
//                .excludePathPatterns("*")
//                .addPathPatterns("/admin/**")
                ;
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.
                addMapping("/**")
                .allowCredentials(true)
                .allowedMethods("GET","POST","PUT","DELETE")
                .allowedOriginPatterns("*")
                .allowedHeaders("*")
                .allowedHeaders("Content-Type", "X-Requested-With", "accept,Origin",
                        "Access-Control-Request-Method", "Access-Control-Request-Headers", "token");
    }
}
